package com.example.distillapplication.data.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.example.distillapplication.data.entity.OperationLog;
import com.example.distillapplication.data.entity.UserInfo;
import com.example.distillapplication.data.repository.DataBaseListener;
import com.example.distillapplication.data.repository.DataBaseRepository;

import java.util.List;

//数据库操作
public class DataBaseViewModel extends AndroidViewModel implements DataBaseListener {
    public LiveData<List<UserInfo>> allUserInfo = new MutableLiveData<>();//所有用户信息
    public LiveData<List<OperationLog>> allOperationLog = new MutableLiveData<>();//所有日志信息
    public LiveData<List<UserInfo>> userInfoByAccount = new MutableLiveData<>();//通过账号得到的用户信息
    public LiveData<List<OperationLog>> operationLogByID = new MutableLiveData<>();//通过ID得到的操作日志

    public DataBaseRepository dataBaseRepository;//访问数据库的数据仓库实体

    public DataBaseViewModel(@NonNull Application application) {
        super(application);
        dataBaseRepository=new DataBaseRepository(application, this);
    }


    @Override
    public void setAllUserInfo(LiveData<List<UserInfo>> allUserInfo) {
        this.allUserInfo = allUserInfo;
    }

    @Override
    public void setAllOperationLog(LiveData<List<OperationLog>> allOperationLog) {
        this.allOperationLog = allOperationLog;
    }

    @Override
    public void setUserInfoByAccount(LiveData<List<UserInfo>> userInfoByAccount) {
        this.userInfoByAccount = userInfoByAccount;
    }

    @Override
    public void setOperationLogByID(LiveData<List<OperationLog>> operationLogByID) {
        this.operationLogByID = operationLogByID;
    }
}
